/*******************************************************************************
 ** Name: weapon.cpp                                                       **
 ** Description: WorldObject-derived container objects                        **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $$HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2011  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.                                                      **
 ******************************************************************************/
// Modified $Date: 2011-11-24 00:07:02 -0700 (Thu, 24 Nov 2011) $ by $Author: unknown $
#define _weapon_cpp_ID    "$Id: weapon.cpp 63608 2011-11-24 07:07:02Z unknown $"

#include "weapon.hpp"

static const char *  ammoType[] =
{
    "Full-metal Jacket", "Jacketed Hollowpoint", "Armor Piercing",
    "High Explosive Incendiary", "Flechette", "Less-Than-Lethal",
    "00 Buckshot", "Concussion", "Blank", "Smoke", "Flare",
    "Incendiary", "CS Gas", "Sabot Slug", "Frangible",
    "FMJ", "JHP", "AP", "HEI", "FLE", "LTL", "BUCK", "CONC",
    "BLANK", "SMOKE", "FLARE", "INC", "CS", "SABO", "FRAN"
};

static const char *  dmgType[] =
{
    "Ballistic", "Piercing", "Slashing", "Bludgeoning"
};
static const char *  wpnClass[] = { "Melee", "Ranged" };
static const char *  wpnType[] =
{
    "Improvised", "Axe", "Mace", "Sword", "Spear", "Nunchuku",
    "Knife", "Knuckles", "Club", "Exotic Melee",
    "Handgun", "Assault Rifle", "Bolt-action Rifle", "Sniper Rifle",
    "Shotgun", "Submachine gun", "Machine gun", "Explosives",
    "Hurled", "ExoticRanged"
};

static const char *  wpnFireRate[] = { "Safety", "Single", "Burst", "Auto" };


//////////////////////////[ RangedWeapon
RangedWeapon::RangedWeapon(std::string n)
    : Weapon(n)
{
    recoil      = 0;
    rate        = WpnFireRate::Single;
    selector    = WpnFireRate::Safety;
    wclass      = WpnClass::Ranged;
}

RangedWeapon::RangedWeapon(std::string n, WpnType t, WpnHands h,WpnFireRate fr)
    : Weapon(n,t,h,WpnClass::Ranged,WpnDamage::Ballistic,OType::RangedWeapon)
{
    recoil = 0;
    rate = fr;
    selector = WpnFireRate::Safety;
}

void
RangedWeapon::SetFireRate(WpnFireRate fr)
{
//   if (BCHK((uint8_t)rate,(uint8_t)fr))
        selector = fr;
}

std::string
RangedWeapon::FireRate(WpnFireRate fr)
{
    return wpnFireRate[(uint8_t)fr];
}

int
RangedWeapon::Actionable(std::string cmd, Client * player)
{

}

//////////////////////////[ MeleeWeapon
MeleeWeapon::MeleeWeapon(std::string n,WpnType t,WpnHands h,WpnDamage wd,int s,int d)
    : Weapon(n,t,h,WpnClass::Melee,wd,OType::MeleeWeapon)
{
    minStr = s;
    minDex = d;
}

MeleeWeapon::MeleeWeapon(std::string n)
    : Weapon(n)
{
    minStr = 0;
    minDex = 0;
    wclass = WpnClass::Melee;
}


//////////////////////////[ Ammo

const char *
Ammo::Type(AmmoType at)
{
    return ammoType[(uint8_t)at];
}

const char *
Ammo::TypeAbbr(AmmoType at)
{
    return ammoType[(uint8_t)at+((uint8_t)AmmoType::max)-1];
}

Ammo::Ammo(AmmoType at,char m,int r)
{
    type = at; container = m; rounds = r; 
}


//////////////////////////[ Weapon

void
Weapon::AddTrait(Trait * t)
{
    t->next = traits;
    traits = t;
}

std::string
Weapon::FQType()
{
   std::string     str;
   str = TypeToStr();
   str += ":";
   str += WpnClassToStr(wclass);
   str += ":";
   str += SubTypeToStr(wtype);
   return str;
}

std::string
Weapon::WpnClassToStr(WpnClass wc)
{
    return wpnClass[(uint8_t)wc];
}

std::string
Weapon::SubTypeToStr(WpnType wt)
{
    return wpnType[(uint8_t)wt];
}

std::string
Weapon::DamageType(WpnDamage dt)
{
    return dmgType[(uint8_t)dt];
}

Weapon::Weapon(std::string n,WpnType wt,WpnHands wh,WpnClass wc,WpnDamage wd, OType t)
        : WorldObject(t,n)
{
    wtype = wt; hands = wh; wclass = wc; wdmg = wd;
    range = 0; cost = 0; traits = NULL; dmg.rolls=1; dmg.num=6;
}


Weapon::Weapon(std::string n)
    : WorldObject(OType::Weapon,n)
{
    wtype = WpnType::max;
    hands = WpnHands::One;
    wclass = WpnClass::Ranged;
    wdmg = WpnDamage::Ballistic;
    range = 0; cost = 0; traits = NULL; dmg.rolls=1; dmg.num=0;
}

Weapon::Weapon(const Weapon& orig)
{
}

Weapon::~Weapon()
{
}

